Skip to content

Conversation

@oleibman
Copy link
Collaborator

@oleibman oleibman commented Oct 31, 2025

Fix #4696. Fix #917 (which had gone stale but is now reopened). Fix #916. People were receiving unexpected exceptions calling Date::isDateTime($cell). 916 and 917 had been mostly resolved long ago by adding a numeric check on the contents of $cell. However, it turns out that the use of values with very large absolute values can cause Php DateTime to throw an exception, which is the problem with 4696, when it calls Date::exceTolDateTimeObject for a cell with a large integer value.

Date::excelToDateTimeObject is coded to return a Php DateTime object. I don't see any reasonable non-breaking fix for that. People can always add try/catch if they are worried about that. However, Date::isDateTime can add an additional check and return false if this situation occurs. All 3 of the issues resolved by this PR mention isDateTime in their discussion; they are all fixed without additional coding changes by this.

An additional change is needed for Cell::getFormattedValue to avoid this problem. This is fixed in Style::NumberFormatter::DateFormatter::format.

This is:

  • a bugfix
  • a new feature
  • refactoring
  • additional unit tests

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
  • Documentation is updated as necessary

Fix PHPOffice#4696. Fix PHPOffice#917 (which had gone stale but is now reopened). Fix PHPOffice#916. People were receiving unexpected exceptions calling `Date::isDateTime($cell)`. 916 and 917 had been mostly resolved long ago by adding a numeric check on the contents of $cell. However, it turns out that the use of values with very large absolute values can cause Php DateTime to throw an exception, which is the problem with 4696, when it calls `Date::toExcelDateTimeObject` for a cell with a large integer value.

`Date::toExcelDateTimeObject` is coded to return a Php DateTime object. I don't see any reasonable non-breaking fix for that. People can always add try/catch if they are worried about that. However, `Date::isDateTime` can add an additional check and return `false` if this situation occurs. All 3 of the issues resolved by this PR mention isDateTime in their discussion; they are all fixed without additional coding changes by this.

An additional change is needed for `Cell::getFormattedValue` to avoid this problem. This is fixed in `Style::NumberFormatter::DateFormatter::format`.
@oleibman oleibman added this pull request to the merge queue Nov 2, 2025
Merged via the queue into PHPOffice:master with commit c944b1a Nov 2, 2025
14 checks passed
@oleibman oleibman deleted the issue4696 branch November 2, 2025 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Date::excelToDateTimeObject fatal errorstale Date::excelToDateTimeObject fatal error Date::isDateTime returns true for string: abr01.html

1 participant